package dao;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.stereotype.Repository;
import pojo.MedicalAdvice;
import pojo.Schedule;

import java.util.List;
@Repository
public class MedicalAdviceDAO extends  BaseDAO<MedicalAdvice> {
    public MedicalAdviceDAO() {
        super(MedicalAdvice.class);
    }
    public List<MedicalAdvice> queryByMedical(MedicalAdvice medicalAdvice) {
        return getHibernateTemplate().execute(new HibernateCallback<List<MedicalAdvice>>() {
            @Override
            public List<MedicalAdvice> doInHibernate(Session session) throws HibernateException {
                List<MedicalAdvice> list = session.createQuery("from MedicalAdvice where user_id=:xx")
                        .setParameter("xx", medicalAdvice.getUserId()).list();
                return list;
            }
        });
    }

    public List<MedicalAdvice> queryByYz(MedicalAdvice medicalAdvice) {
        return getHibernateTemplate().execute(new HibernateCallback<List<MedicalAdvice>>() {
            @Override
            public List<MedicalAdvice> doInHibernate(Session session) throws HibernateException {
                List<MedicalAdvice> list = session.createQuery("from MedicalAdvice where registry.id=:xx ")
                        .setParameter("xx", medicalAdvice.getRegistry().getId()).list();
                return list;
            }
        });
    }
}
